﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AiFrame.InterfaceLib.MVP;
using AiFrameDemo.Contacts.Core.ViewModel;
using AiFrameDemo.Contacts.Core.Views;

namespace AiFrameDemo.Contacts.WinForms.Windows
{
    public partial class ContactDataWindow : Form, IContactDataView
    {
        private ContactDataViewModel _viewModel;

        public ContactDataWindow()
        {
            InitializeComponent();
        }

        public void BindToViewModel(ContactDataViewModel viewModel)
        {
            _viewModel = viewModel;
            allCustomersCmb.DataSource = _viewModel.CustomerListValues;
            allCustomersCmb.DisplayMember = "value";
            allCustomersCmb.ValueMember = "Key";
            BindingHelper.SetBinding(allCustomersCmb, "SelectedValue", _viewModel, "Customer", true, DataSourceUpdateMode.OnPropertyChanged);

            BindingHelper.SetBinding(contactMessageTb, "Text", _viewModel, "Content", true, DataSourceUpdateMode.OnPropertyChanged);
            BindingHelper.SetBinding(okBtn, "Enabled", _viewModel, "CanSave", true, DataSourceUpdateMode.OnPropertyChanged);
        }

        private void okBtn_Click(object sender, EventArgs e)
        {
            _viewModel.UserWantsToSave();
        }

        public void DisplayError(string message)
        {
            MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        public void ShowView()
        {
            ShowDialog();
        }

        public void SetCaption(string s)
        {
            this.Text = s;
        }

        public void InformUser(string message)
        {
            MessageBox.Show(message);
        }
    }
}
